$(function(){
	resizeWidth()

	var nullStr = "-";
	var $lotteryList = $("#lotteryList");
	var trDetach = $lotteryList.find("tr:first-of-type").detach();
	var pageNo = 1;
	var dataCount = 20;
	var seachControl = true;
	var reg = /^[1-9]\d{13}$/;
	var sTime='';

	//查询按钮
	$("#btn_search").on("click",function(){
		sTime = $("#search_time").val();
		if(sTime == ""){
			alert("请输入要查询的时间！");
			return;
		}else if(!reg.test(sTime)){
			alert("查询的时间格式错误！");
			return;
		}
		$lotteryList.empty();
		getLotteryData(pageNo);
	});

	//获取数据
	function getLotteryData($pageNo){
		if(!seachControl){
			return;
		}
		// seachControl = true;
		$.ajax({
			type:'get',
			dataType:'json',
			url:'/index.php?d=backstage&c=goldtimes/selectTimeBet',
			data:{
				time: sTime,
			},
			success:function(res){
				$lotteryList.empty();
				$(".table_box").css("height","auto");
				$(".table_box .sequence_list").css("height","auto");
				if(res.code == '200'){
					if(!$.isEmptyObject(res.data)){
						renderLotteryList(res.data);
						InitTableHeight();
					}else{
						noDataTipShow($lotteryList);
					}
				}else{
					noDataTipShow($lotteryList,res.msg);
				}
				
			},
			beforeSend:function(){
				noDataTipHide();
				loadingShow();
			},
			complete:function(){
				loadingHide()
			}
		});
	};

	//渲染数据表
	function renderLotteryList($data){
		var item = $data;  
			var tr = trDetach.clone();
			tr.find(".tvmid").text(item.qid?item.qid:nullStr);
			tr.find(".goldtime").text(item.goldtime?item.goldtime:nullStr);
			tr.find(".seedcount").text(item.seedcount?item.seedcount:nullStr);
			tr.find(".winnernumber").text(item.winnernumber?item.winnernumber:nullStr);
			tr.find(".actiontime").text(item.actiontime?item.actiontime:nullStr);
			tr.appendTo($lotteryList);
	};

	//分页
	function renderPage(data){
		var totalPage = data.total ? Math.ceil(data.total/data.count): 1;
		var page = data.page ? data.page: 1;

		$("#page").createPage({
		    pageCount: totalPage,
	        current: page,
	        backFn: function(p) {
	            getLotteryData(p)
	        }
		})
	};
	
});